IF OBJECT_ID(N'ssf.cmd_dir_xquery') IS NOT NULL
	DROP FUNCTION ssf.cmd_dir_xquery
GO

CREATE FUNCTION ssf.cmd_dir_xquery (
	@dir XML
)
RETURNS TABLE
AS
/*
<object_header>

<object_summary>
	<purpose><![CDATA[
Return XML result of ssf.cmd_dir in table format.
	]]></purpose>
</object_summary>

</object_header>
*/

	RETURN (	
		SELECT dir.value(N'@name', N'NVARCHAR(2048)') AS directory
			, content.value(N'@name', N'NVARCHAR(2048)') AS name
			, content.value(N'(timefield/text())[1]', N'DATETIME') AS timefield
			, content.value(N'(directory_fl/text())[1]', N'BIT') AS directory_fl
			, content.value(N'(size/text())[1]', N'BIGINT') AS size
		FROM @dir.nodes(N'/cmd_dir/directory') AS d(dir)
		CROSS APPLY dir.nodes(N'content') AS c(content)
	)
GO
